package util.hibernate;
public class StringToHTMLString {
	
	public static void main(String[] args) {
		System.out.println();
	}
	
	public static String stringToHTMLString(String string) {
		
	    StringBuffer sb = new StringBuffer(string.length());

	    boolean blankCharacter = false;
	    
	    int len = string.length();
	    char c;

	    for (int i = 0; i < len; i++) {
	    	
	        c = string.charAt(i);
	        if (c == ' ') {

	            if (blankCharacter) {
	                blankCharacter = false;
	                sb.append("&nbsp;");
	            } else {
	                blankCharacter = true;
	                sb.append(' ');
	            }
	            
	        } else {
	        	
	            blankCharacter = false;

	            if (c == '"') {
	                sb.append("&quot;");
	            } else if (c == '>') {
	                sb.append("&gt;");
	            } else if (c == '&') {
	                sb.append("&amp;");
	            } else if (c == '<') {
	                sb.append("&lt;");
	            } else if (c == '\n') {
	                sb.append("&lt;br/&gt;");
	            } else {
	            	
	                int temp = 0xffff & c;
	                if (temp < 160) {
	                    //normal
	                    sb.append(c);
	                } else {
	                    //get unicode
	                    sb.append("&#");
	                    sb.append(new Integer(temp).toString());
	                    sb.append(';');
	                }
	                
	            }
	        }
	    }
	    
	    return sb.toString();
	    
	}
	
}